<%-- 
    Document   : substitute
    Created on : 13/Mai/2010, 17:01:14
    Author     : luis
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"
    import="pt.our.angemc.parser.*"
    import="pt.our.angemc.datatypes.*"
    import="org.json.*"

%>

<%
    JSONObject obj = new JSONObject();
    String text = request.getParameter("text");
    String oldS = request.getParameter("oldS");
    String newS = request.getParameter("newS");

    Parser2 p = new Parser2();

    if(p.checkGrammar(text).equals("0"))
    {
        try
        {
            Grammar g = p.substitute(text, oldS, newS);
            obj.put("success", true);
            obj.put("subs",g.toString());
        }
        catch(Exception e)
        {
            
                obj.put("success", false);
                obj.put("error",e.getMessage());
            
        }

    }
    else
    {
        obj.put("success", false);
    }
    out.print(obj);
%>
